#!/usr/bin/python

import sys
import matplotlib.pyplot as plt
import pylab
import random

filename = sys.argv[1]
f = open(filename, "rU")
fl = f.readlines()

x1 = []
x2 = []
y1 = []
y2 = []

MIN = 2040560
MAX = 2090270

for i, line in enumerate(fl):
    l = line.split('\t')
    start = int(l[0])
    stop = int(l[1].rstrip())
    x1.append(start)
    x2.append(stop)
#    increment = random.uniform(5, 15)
    increment = 2 + (i * 0.01)
    y1.append(increment)
    y2.append(increment)

gx = [1,4721396]
gy = [1,1]

y1.sort()
y2.sort()

a = [x1, x2]
b = [y1, y2]

fig = plt.figure(1, figsize=(14,8))

plt.subplot(211)
plt.plot(gx, gy, color='blue', marker='|', markersize=8.0,
    mec='black', ls='-', lw=2.0)
#plt.plot(x, y, 'g>') 
plt.plot(a, b, color='purple', linestyle='-')
plt.axis([1, 4721396, 0, 620])
plt.title('Paired-end clones')
#plt.xlabel('Genome coordinates(bp)')
plt.ylabel('Tiled clone pairs')
plt.axvspan(MIN, MAX, facecolor='green', alpha=0.3)

frame1 = plt.gca()
for tick in frame1.axes.get_yticklines():
    tick.set_visible(False)
for y in frame1.axes.get_yticklabels():
    y.set_visible(False)

plt.grid(True)

subx1 = []
subx2 = []
suby1 = []
suby2 = []

for index, value in enumerate(x1):
    if MIN <= x1[index] <= MAX:
        subx1.append(x1[index])
        subx2.append(x2[index])
        suby1.append(y1[index])
        suby2.append(y2[index])

a1 = [subx1, subx2]
b1 = [suby1, suby2]

plt.subplot(212)

plt.plot(a1, b1, color='purple', marker='>', markersize=8.0,
    mec='black', ls=':', lw=2.0)
plt.axis([MIN, MAX, min(suby1)-0.03, max(suby1)+0.03])
plt.xlabel('Genome coordinates(bp)')
plt.ylabel('Tiled clone pairs')
frame2 = plt.gca()
for tick in frame2.axes.get_yticklines():
    tick.set_visible(False)
for y in frame2.axes.get_yticklabels():
    y.set_visible(False)
plt.grid(True)

plt.show()

